<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<script language="JavaScript" type="text/javascript">
function fatorial (numero) {
 	//if (numero==0) return 1;	
	//else return numero*fatorial(numero-1);
	//while(numero != 0) {
		Math.floor(numero/3);
	//}
}

function int_to_bin(num) {
	var binario = new Array (8);
	for (var j= 0; j<8; j++) binario[j] = 0;
	var i=0;
	while (num != 0) {
		binario[7-i] = num%2;	
		num = Math.floor(num/2);
		i++;
	}
	document.getElementById("tela").innerHTML+=" ";
	for (var j= 0; j<8; j++)
		document.getElementById("tela").innerHTML+=binario[j];
}

function soma_binario( bin1, bin2 ) {
	var i = 0, resto = 0;
	var soma = new Array ( 8 );
	
	while(bin1!=0||bin2!=0){
		soma[i++]=(bin1%10+bin2%10+resto)%2;
		resto=Math.floor((bin1%10+bin2%10+resto)/2);
		bin1=Math.floor(bin1/10);
		bin2=Math.floor(bin2/10);
		document.getElementById("tela").innerHTML+=soma;
		document.getElementById("tela").innerHTML+=resto;
		document.getElementById("tela").innerHTML+=bin1;
		document.getElementById("tela").innerHTML+=bin2;
	}
	
	if( resto != 0 ) {
		soma[i++] = resto;
	}
	
	--i;
	document.getElementById("tela").innerHTML+=soma[i--];
	return soma;
	
	while(i>=0){
		document.getElementById("tela").innerHTML+=soma[i--];
	}
}

/*
function mult_bin(){
	var bin1=11,bin2=10; // ENTRA COM DOIS BINÁRIOS;
	var multpli = new Array[20];
	var digit, fator=1;
	
	while(bin2!=0){	
		digit = Math.floor(bin2%10);
		
		if(digit==1){
		bin1=bin1*fator;
		if (somabinario(bin1,multpli) != undefined)
		multpli=somabinario(bin1,multpli);
			
		}
		
		else{
			bin1=bin1*fator;
			
		}
		
		bin2=Math.floor(bin2/10);
		fator=10;
	}
	for(var i=8; i>=0; i--)
	{
		
		
		
		
	}
	//for (var i=0; i<8; i++) {
		
	document.getElementById("tela").innerHTML+= multpli;
	//}
	
}
*/

/*function convert_dec_to_bin(){
	var bin= Array (100);
	var dec=15;
	var i=0;
	var quocient =dec ;
	
	while(quocient != 0){
		bin[i] = quocient % 2;
		quocient = Math.floor(quocient / 2);
		i++;
	}
	i--;
	while(i>=0){
		document.getElementById("tela").innerHTML+=bin[i];
		i--;
	}

}*/

</script>
<body>
<div id="tela">
<br />
</div>
<div id="teclado">
<button onclick="int_to_bin(7)">7</button> <button onclick="int_to_bin(8)">8</button> <button onclick="int_to_bin(9)">9</button> <br />
<button onclick="int_to_bin(4)">4</button> <button onclick="int_to_bin(5)">5</button> <button onclick="int_to_bin(6)">6</button> <br />
<button onclick="int_to_bin(1)">1</button> <button onclick="int_to_bin(2)">2</button> <button onclick="int_to_bin(3)">3</button> <br />
<button onclick="int_to_bin(0)" style="width:101px;">0</button> <br />

<button onclick="soma_binario(10,10)" style="width:101px;">Assunça</button> <br />
<button onclick="convert_dec_to_bin()" style="width:101px;">Raj culhado</button> <br />
<button onclick="mult_bin()" style="width:101px;">Xaringan</button> <br />
</div>
</body>
</html>
